"""

"""

from .data import Data
from typing import List, Union

from sympy import Matrix, ones


class LinearRegression:
    def __init__(self, X: Union[Data, List[Data]], Y: Data, *args, **kwargs) -> None:
        if isinstance(X[0], list):
            if len(X) <= len(X[0]):
                raise ValueError("数据点太少！")
        else:
            X = [X]

        self.X = X
        self.Y = Y

    @property
    def variable_number(self) -> int:
        return len(self.X)

    @property
    def size(self) -> int:
        return len(self.X[0])

    @property
    def coeffs(self) -> Data:
        A = Matrix([ones(1, self.size), Matrix(self.X)]).T
        AT = A.T
        if (AT * A).rank() == self.variable_number + 1:
            return Data((AT * A).inv() * AT * Matrix(self.Y))
